package org.example.springboot.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.springboot.common.page.PageResult;
import org.example.springboot.common.utils.Result;
import org.example.springboot.convert.IrrigationStatConvert;
import org.example.springboot.query.IrrigationStatQuery;
import org.example.springboot.service.IrrigationStatService;
import org.example.springboot.vo.IrrigationStatVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Fz
 * @since 1.0.0 2024-08-05
 */
@Slf4j
@RestController
@RequestMapping("/irrigation-stat")
@AllArgsConstructor
public class IrrigationStatController {

    private final IrrigationStatService irrigationStatService;

    @PostMapping("page")
    public Result<PageResult<IrrigationStatVO>> page(@RequestBody @Valid IrrigationStatQuery query) {
        PageResult<IrrigationStatVO> page = irrigationStatService.page(query);
        return Result.ok(page);
    }

    @PostMapping("/add")
    @Operation(summary = "更新数据统计数据")
    public Result<String> save(@RequestBody IrrigationStatVO vo) {
        irrigationStatService.save(IrrigationStatConvert.INSTANCE.convert(vo));
        return Result.ok();
    }

}